﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections.Specialized;


namespace _1
{
    public partial class FDelAndRen : Form
    {
        private string path = @"D:\Malefic\ОС\TestFolder";
        private DateTime date = DateTime.Now;

        private void ChangeName(string FileName, string AddedString)
        {
            int i = 0, j = 0;
            string ds = "", ResultFileName = "";
            for (i = FileName.Length - 1; i >= 0; i--)
            {
                if (FileName[i] == '.')
                {
                    ds = "";
                    ResultFileName = "";
                    for (j = 0; j < i; j++)
                    {
                        ResultFileName += FileName[j];
                    }
                    for (j = i; j < FileName.Length; j++)
                    {
                        ds += FileName[j];
                    }
                    ResultFileName += AddedString + ds;
                }
            }
            File.Move(FileName, ResultFileName);
        }

        public FDelAndRen()
        {
            InitializeComponent();
            LDirChousen.Text = path;
            LDateChousen.Text = date.ToShortDateString();
        }

        private void BDelAndRen_Click(object sender, EventArgs e)
        {
            DGWStatusShower.RowCount = 0;
            DirectoryInfo directory = new DirectoryInfo(path);
            Renamer r = new Renamer();
            r.Raname(path,date);
            //FileInfo[] files = directory.GetFiles();
            //for (int i = 0; i < files.Length; i++)
            //{
            //    DGWStatusShower.RowCount++;
            //    DGWStatusShower.Rows[i].Cells[0].Value = files[i].Name;
            //    if (files[i].LastWriteTime < date)
            //    {
            //        DGWStatusShower.Rows[i].Cells[1].Value = "удалён";
            //        File.Delete(files[i].FullName);
            //    }
            //    else
            //    {
            //        DGWStatusShower.Rows[i].Cells[1].Value = "переименован";
            //        ChangeName(files[i].FullName, date.ToShortDateString());
            //        files = directory.GetFiles();
            //        DGWStatusShower.Rows[i].Cells[0].Value = files[i].Name;
            //    }                
            //}
            //DGWStatusShower.RowCount = r.NVClist.Count;
            int i=0;
            for (i = 0; i < r.NVClist.Count; i++)
            {
                DGWStatusShower.RowCount++;
                DGWStatusShower.Rows[i].Cells[0].Value = r.NVClist.GetValues(i);
                DGWStatusShower.Rows[i].Cells[1].Value = r.NVClist.GetKey(i);
            }
        }

        private void DTPDateChouse_ValueChanged(object sender, EventArgs e)
        {
            date = DTPDateChouse.Value;
            LDateChousen.Text = date.ToShortDateString();
        }

        private void BBDirChouse_Click(object sender, EventArgs e)
        {
            FBDDirChouse.ShowDialog();
            if (Directory.Exists(FBDDirChouse.SelectedPath))
            {
                path = FBDDirChouse.SelectedPath;
                LDirChousen.Text = path;
            }           
        }
    }
}
